<?php
/**
 * Created by 长毋相忘c.
 * 文件用途描述 :
 * Date: 2018/2/18/018
 * Time: 11:57
 */

namespace app\api\controller\v1;


use app\api\service\AppToken;
use app\api\service\Token as TokenService;
use app\api\service\UserToken;
use app\api\validate\AppTokenGet;
use app\api\validate\TokenGet;
use app\lib\exception\ParameterException;

class TokenController
{
    /**
     * 第三方应用获取令牌
     * @url /app_token?
     * @POST ac=:ac se=:secret
     */
    public function getAppToken($ac='', $se='')
    {
        (new AppTokenGet())->goCheck();
        $app = new AppToken();
        $token = $app->get($ac, $se);
        return [
            'token' => $token
        ];
    }

   public function getToken($code=''){
       (new TokenGet())->goCheck();
       $ut=new UserToken($code);
       $token=$ut->getToken();
       return [
           'token'=>$token
        ];
   }

   public function verifyToken($token=''){
       if(!$token){
           throw new ParameterException([
               'token不允许为空！'
           ]);
           $valid=TokenService::verifyToken($token);
           return[
               'isValid'=>$valid
           ];
       }
   }
}